import 'package:flutter/material.dart';
import 'package:lovelife/entities/customTab.dart';
import './tabMainPages/loveChat.dart';
import './tabMainPages/loveMySelf.dart';
import './tabMainPages/loveRead.dart';
import './tabMainPages/loveWatch.dart';

class Home extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return new _HomeState();
  }
}

class _HomeState extends State<Home> with TickerProviderStateMixin {
  TabController _bottomTabController;

  List<CustomTab> _customTabs = <CustomTab>[
    new CustomTab(title: 'Read', icon: Icons.apps, tabPage: new LoveRead()),
    new CustomTab(title: 'Watch', icon: Icons.tv, tabPage: new LoveWatch()),
    new CustomTab(title: 'Message', icon: Icons.message, tabPage: new LoveChat()),
    new CustomTab(title: 'Self', icon: Icons.person, tabPage: new LoveMySelf()),
  ];

  @override
  void initState() {
    // TODO: implement initState
    _bottomTabController =
        new TabController(length: _customTabs.length, vsync: this);
    super.initState();
  }

  @override
  void dispose() {
    // TODO: implement dispose
    _bottomTabController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return new Scaffold(
      body: new TabBarView(
        controller: _bottomTabController,
        children: _customTabs.map((CustomTab custom) {
          return custom.tabPage;
        }).toList(),
      ),
      bottomNavigationBar: new Material(
        color: Colors.lightBlue,
        child: new TabBar(
          indicatorColor: Colors.white,
          controller: _bottomTabController,
          tabs: _customTabs.map((CustomTab custom) {
            return new Tab(
              text: custom.title,
              icon: new Icon(custom.icon),
            );
          }).toList(),
        ),
      ),
    );
  }
}
